<template>
        <!-- 
      <el-button type="primary" style="margin-left: 16px" @click="drawer = true">
        open
      </el-button> -->

       <el-avatar shape="square" :size="100" :src="imgurl" @click="drawer = true">
        <img src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" alt="">
        </el-avatar>
      <el-drawer
        v-model="drawer"
        title="图片库"
        direction="ttb"
        size="40%"
      >
       
     
      <el-upload v-model:file-list="fileList" 
                list-type="picture-card" 
                :auto-upload="false"
                :on-change="onChange">
        <el-icon><Plus /></el-icon>

        <template #file="{ file }">
          <div>
            <img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
            <span class="el-upload-list__item-actions">
              <span
                class="el-upload-list__item-preview"
                @click="getImgUrl(file.url)"
              >
                <el-icon><zoom-in /></el-icon>
              </span>
            </span>
          </div>
        </template>
      </el-upload>
       </el-drawer>
</template>
<script setup lang="ts">
import { ref } from 'vue';
const drawer = ref(false)
const imgurl=ref("")
const fileList = ref([
    {
        name: 'food.jpeg',
        url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100',
    },
])
const getImgUrl = (imageUrl:string) => { 
    console.log(imageUrl);
    imgurl.value = imageUrl //头像赋值
    drawer.value=false
}
const onChange = (uploadFile: any, uploadFiles: any) => { 
    console.log("点击操作==", uploadFile);
    let name = uploadFile.name
    let file = uploadFile.raw
    //读取图片
    let reader = new FileReader()
    reader.readAsDataURL(file)
    //使用onLoad 提取base64
    reader.onload = () => { 
        console.log(reader.result);
        
    }

}
</script>
<style scoped></style>